package com.xneure.code;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import javax.imageio.ImageIO;
import com.xneure.code.algorithm.Descartes;
import com.xneure.code.image.ImgTools;
import com.xneure.code.log.DefaultHandle;
import com.xneure.code.log.ILog;
import com.xneure.code.log.LogManage;
import com.xneure.tools.Javap;
import com.xneure.utils.FileUtil;
import com.xneure.utils.cipher.SimpleEncode;

public class TestXneure{
	Thread run;

	public static void main(String[] args) throws Exception{
//		TestXneure tx = new TestXneure();
		Class<?>[] c = new Class<?>[] {String.class,String.class};
		System.out.println(c.getClass().newInstance());
	}

	boolean isNull(byte[] b,int off,int len){
		byte[] lineSeparator = "\r\t".getBytes();
		if(len - off == lineSeparator.length){
			for(int i = off;i < lineSeparator.length;i++){
				if(b[i] != lineSeparator[i - off]){
					return false;
				}
			}
			return true;
		}else{
			return false;
		}
	}
	void img() {
		ImgTools demo = new ImgTools();
		BufferedImage img;
		try{
			img = ImageIO.read(new File("d:/1.jpg"));
			ImageIO.write(demo.binaryImage(img),"jpg",new FileOutputStream("d:/2.jpg")) ;  
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	void out() throws IOException{
		ILog b = agentSysOut();
		System.out.println("bb");
		b.debug("sss");
	}

	ILog agentSysOut(){
		ILog log = LogManage.newLog();
		LogManage.monitorSystemOut();
		LogManage.registerWatcher(new DefaultHandle());
		return log;
	}

	void arr(){
		Javap javapTask = new Javap();
		javapTask.setOptions(new String[]{"-c"});
		System.err.println(javapTask.decompilation(TestXneure.class));
	}

	void loadClass(){
		byte[] bytes = FileUtil.readFile(new File("D:\\程序代码\\xneure\\com.xneure.code\\target\\classes\\com\\xneure\\code\\RemoteDebug.class"));
		String data = SimpleEncode.encodeBase64(bytes);
		FileUtil.writeFile(new File("D:\\程序代码\\xneure\\com.xneure.code\\src\\main\\resource\\apache.key"),data,"utf-8",false);
	}

	void timeMapTest() throws InterruptedException{
		CacheMap<String,Integer> tm = new CacheMap<String,Integer>();
		for(int i = 0;i < 10;i++){
			if(i < 5){
				tm.put(String.valueOf(i),i,1000);
			}else{
				tm.put(String.valueOf(i),i);
			}
		}
		for(String val:tm.keySet()){
			System.out.println(val);
		}
		Thread.sleep(10000 + 1000);
		for(String val:tm.keySet()){
			System.err.println(val);
		}
	}

	void cartesianIterator(){
		String[][] a = new String[5][10];
		for(int i = 0;i < a.length;i++){
			for(int j = 0;j < a[i].length;j++){
				a[i][j] = String.valueOf(j);
			}
		}
		long time = System.currentTimeMillis();
		Descartes<String> it = new Descartes<String>(a);
		while(it.hasNext()){
			String[] result = it.next();
			System.err.println(Arrays.toString(result));
		}
		System.out.println(System.currentTimeMillis() - time);
		System.err.println(it.getSize());
	}
}
